{extend name="Public:content"}
{block name="button"}
<!--工具栏 start-->
<div class="row">
    <div class="col-sm-12 m-b-xs">
        <button class="btn btn-white btn-sm" type="button"  onClick="$.Oa.reload()"><i class="fa fa-refresh"></i> 刷新</button>
    </div>
</div>
<!--工具栏 end-->
{/block}
<!--搜索栏 start-->
{block name="search"}
<form id="thumb_search_form">
    <div class="row">
        <div class="col-sm-4 m-b-xs">
            <div class="input-group m-b"><span class="input-group-addon">图片编号</span>
                <input name="title" placeholder="请输入图片编号" class="form-control">
            </div>
        </div>
        <div class="col-sm-3 m-b-xs">
            <div class="input-group m-b"><span class="input-group-addon">账号</span>
                <input name="nickname" placeholder="请输入账号名称" class="form-control">
            </div>
        </div>
        <div class="col-sm-3 m-b-xs">
            <div class="input-group m-b"><span class="input-group-addon">所属分类</span>
                <select name='catid' class='form-control m-b'>
                    <option value=''> 所有 </option>
                    {foreach $cates as $cate}
                    {eq name='cate.id' value='$vo.pid|default=0'}
                    <option value='{$cate.id}' {eq name="cate.id" value="$get_catid|default=0"}selected{/eq}>{$cate.spl}{$cate.cate}</option>
                    {else}
                    <option value='{$cate.id}' {eq name="cate.id" value="$get_catid|default=0"}selected{/eq}>{$cate.spl}{$cate.cate}</option>
                    {/eq}
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="col-sm-6 m-b-xs">
            <div class="input-group m-b"><span class="input-group-addon">审核状态</span>
                <select name='status' class='form-control m-b' style="width: 30%">
                    <option value=''> 所有 </option>
                    {volist name="status_arr" id="status"}
                    <option value="{$key}">{$status}</option>
                    {/volist}
                </select>
                <button type="button" class="btn btn-info" style="margin-bottom: 0px; margin-left: 10px;" onclick="thumb_index.search()">搜索</button>
            </div>
        </div>
    </div>
</form>
{/block}
<!--搜索栏 end-->
{block name="content"}
<div class="table-responsive" style="overflow-x:initial">
    <table id="thumb_table" ></table>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $("input[class='form-control']").keypress(function (e) {
        var e = e || window.event;
        if (e.keyCode == 13) {
            $(".btn.btn-info").click();
        }
    });

    window.thumb_index = {
        //定义工具栏
        //toolbar: "#thumb_index_toolbar",
        search: function(){ //搜索
            var query_params = {};
            $.each($("#thumb_search_form").serializeArray(),function(){
                query_params[$(this).attr('name')] = $(this).attr('value');
            });
            $('#thumb_table').bootstrapTable('refreshOptions',{
                pageNumber : 1,
                queryParams:function(params){
                    var tmp_params = {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
                    var query = $.extend(true,tmp_params,query_params);
                    return query;
                }
            });
        },
        show: function(id){ //详情页面
            parent.layer.open({
                type: 2,
                title: '{$title} > 详情',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['1100px', '650px'],
                content: '{:url("$classuri/info")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        status: function(id){ //审核页面
            parent.layer.open({
                type: 2,
                title: '{$title} > 审核',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("$classuri/status")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        del: function(_this,id){
            if(!id){
                layer.msg('请选择需要删除的数据');
                return false;
            }
            $.Oa.delete(_this,function(data){
                //删除该行
                $("#thumb_table").bootstrapTable('remove',{field:'id',values:[id]});
            })
        },
        //操作格式化
        opert: function(value,row){
            var rst = '';
            var show_auth= '{:auth("$classuri/show")}';
            var del_auth = '{:auth("$classuri/del")}';
            if(show_auth){
                rst +=  '<a onClick="thumb_index.show('+row.id+')" class="btn btn-outline btn-xs btn-default" title="详情" >详情</a> ';
            }
            if(del_auth) {
                rst +=  '<a onClick="thumb_index.del(this,'+row.id+')" data-href="{:url(\"$classuri/del\")}" data-id="'+row.id+'" class="btn btn-outline btn-xs btn-danger" title="删除" >删除</a>';
            }
            return rst;
        }
    }
    $('#thumb_table').bootstrapTable({
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        url:"{:url(\"$classuri/index\")}",
        pageNumber: 1, //初始化加载第一页，默认第一页
        showRefresh: false,
        pagination:true,//是否分页
        sortOrder: 'desc',
        sidePagination:'server',//指定服务器端分页
        queryParamsType : "",
        queryParams: function(params){
            var query_params = {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
            var catid = "{:isset($get_catid)?$get_catid:''}";
            var free = "{:isset($get_free)?$get_free:''}";
            var nickname = "{:isset($get_nickname)?$get_nickname:''}";
            if(catid != '') query_params['catid'] = catid;
            if(free != '') query_params['is_free'] = free;
            if(nickname != ''){
                query_params['nickname'] = nickname;
                $("input[name='nickname']").val(nickname);
            }

            return query_params;
        },//参数
        pageSize:10,//单页记录数
        pageList:[10,20,30,40],//分页步进值
        // responseHandler:responseHandler,//请求数据成功后，渲染表格前的方法
        columns :[
            {field:'id',title:'图片编号',width: 20},
            {field:'thumb_20',title:'图片',width: 50,formatter:function(value,row){
                return '<a href="'+row.thumb_750+'" target="_blank"><img src="'+value+'" width="20" height="20"/></a>'
            }},
            {field:'category',title:'所属类目',width: 50},
            {field:'catid',title:'所属分类',width: 50},
            {field:'nickname',title:'账号',width: 50},
            {field:'channel',title:'来源',width: 50},
            {field:'is_free',title:'是否免费',width:50,formatter:function(value){
                return value == 1 ? '免费':'付费';
            }},
            {field:'downloads',title:'下载次数',width: 50},
            {field:'collects',title:'收藏次数',width: 50},
            {field:'views',title:'浏览量',width: 50},
            {field:'status',title:'审核状态',align:'center',width: 50,formatter:function(value,row){
                var obj = {1:'通过',2:'拒绝',3:'待审核'};
                var btn_color = {1:'btn-primary',2:'btn-danger',3:'btn-warning'};
                return '<button class="btn '+btn_color[value]+' btn-xs" onclick="thumb_index.status('+row.id+')" id="status" data-pk="'+row.id+'" data-id="'+row.id+'">'+obj[value]+'</button>';
            }},
            {field:'action',title:'操作',width: 100,formatter:thumb_index.opert},
        ],
         onLoadSuccess: function(data){
             $('#thumb_table tbody tr').each(function(i,ob){
                 if(!data.rows[i]){
                     $(ob).attr('title','');
                 }else{
                     $(ob).attr('title',data.rows[i].title);
                 }
             })
         }
    })
</script>
{/block}